package com.imooc.web.controller;

import com.imooc.exception.UserNotExistExpection;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Zqm
 * @Title: ControllerExcepetionHandle
 * @ProjectName imooc-security
 * @date 2018/12/17
 */
@ControllerAdvice
public class ControllerExcepetionHandle {

    @ExceptionHandler(UserNotExistExpection.class)
    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)  //500
    public Map<String,Object> handleUserNotExistExpection(UserNotExistExpection ex){
        Map<String,Object> result=new HashMap<>();
        result.put("id",ex.getId());
        result.put("message",ex.getMessage());
        return result ;
    }
}
